package com.panda.crud.logic.delete.auto.fill.controller;

import com.panda.crud.logic.delete.auto.fill.entity.User;
import com.panda.crud.logic.delete.auto.fill.entity.UserQuery;
import com.panda.crud.logic.delete.auto.fill.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("queryUser")
    public User queryUser(Long id) {
        return userService.queryUser(id);
    }

    @PostMapping("queryUserList")
    public List<User> queryUserList(@RequestBody UserQuery query) {
        return userService.queryUserList(query);
    }

    @PostMapping("addUser")
    public Boolean addUser(@RequestBody User user) {
        return userService.addUser(user);
    }

    @PostMapping("addUsers")
    public Boolean addUsers(@RequestBody List<User> users) {
        return userService.addUsers(users);
    }

    @PostMapping("saveOrUpdateBatch")
    public Boolean saveOrUpdateBatch(@RequestBody List<User> users) {
        return userService.saveOrUpdateBatch(users);
    }

    @PostMapping("updateUserById")
    public Boolean updateUserById(@RequestBody User user) {
        return userService.updateUserById(user);
    }

    @PostMapping("updateUser")
    public Boolean updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @PostMapping("updateBatchById")
    public Boolean updateBatchById(@RequestBody List<User> users) {
        return userService.updateBatchById(users);
    }

    @PostMapping("deleteById")
    public Boolean deleteById(@RequestBody User user) {
        return userService.deleteById(user.getId());
    }

    @PostMapping("deleteUserByIds")
    public Boolean deleteUserByIds(@RequestBody List<Long> ids) {
        return userService.deleteUserByIds(ids);
    }

    @PostMapping("deleteUserById")
    public Boolean deleteUserById(@RequestBody User user) {
        return userService.deleteUserById(user);
    }

    @PostMapping("deleteUser")
    public Boolean deleteUser(@RequestBody User user) {
        return userService.deleteUser(user);
    }
}
